package com.example.myapplication.part15;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.io.File;
import java.util.ArrayList;

public class ListViewAdapter extends BaseAdapter {

    private ArrayList<File> files;
    private LayoutInflater layoutInflater;

    public ListViewAdapter(ArrayList<File> files, LayoutInflater layoutInflater) {
        this.files = files;
        this.layoutInflater = layoutInflater;
    }

    @Override
    public int getCount() {
        return files.size();
    }

    @Override
    public Object getItem(int position) {
        return files.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = layoutInflater.inflate(android.R.layout.simple_list_item_1, parent, false);
        }
        TextView textView = convertView.findViewById(android.R.id.text1);
        textView.setText(files.get(position).getName());
        return convertView;
    }
}